<template>
    <div class="ele-body">
      <el-card shadow="never">
        <!-- 搜索表单 -->
        <el-form
          :model="where"
          label-width="77px"
          class="ele-form-search"
          @keyup.enter.native="reload"
          @submit.native.prevent>
          <el-row :gutter="15">
            <el-col :lg="5" :md="12">
              <el-form-item label="商品名称:">
                <el-input
                  clearable
                  v-model="where.chineseName"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :lg="5" :md="12">
              <el-form-item label="生产厂家:">
                <el-input
                  clearable
                  v-model="where.maker"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :lg="5" :md="12">
              <el-form-item label="批次号:">
                <el-input
                  clearable
                  v-model="where.lot"
                  placeholder=""/>
              </el-form-item>
            </el-col>
          <el-col :lg="5" :md="12">
              <el-form-item label="状态:">
                <el-select
                clearable
                v-model="where.zt"
                placeholder=""
                class="ele-fluid">
                <el-option label="未同步" value="Y"/>
                <el-option label="已同步" value="N"/>
                <el-option label="E" value="E"/>
                <el-option label="H" value="H"/>
                <el-option label="T" value="T"/>
              </el-select>
              </el-form-item>
            </el-col>

          <el-col :lg="4" :md="12">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                size="small"
                @click="reload">查询
              </el-button>
              <el-button @click="reset" size="small">重置</el-button>
            </div>
          </el-col>
        </el-row>
        </el-form>
        <!-- 数据表格 -->
        <ele-pro-table
          ref="table"
          :where="where"
          :datasource="url"
          :columns="columns"
          :selection.sync="selection"
          height="calc(100vh - 270px)">
          <!-- 表头工具栏 -->
          <template slot="toolbar" v-if="false">
            <el-button
              size="small"
              type="primary"
              icon="el-icon-plus"
              class="ele-btn-icon"
              @click="openEdit(null)"
              v-if="permission.includes('sys:c37infkcspphhw:add')">添加
            </el-button>
            <el-button
              size="small"
              type="danger"
              icon="el-icon-delete"
              class="ele-btn-icon"
              @click="removeBatch"
              v-if="permission.includes('sys:c37infkcspphhw:dall')">删除
            </el-button>
          </template>
          <!-- 操作列 -->
          <template slot="action" slot-scope="{row}">
            <el-link
              type="primary"
              :underline="false"
              icon="el-icon-edit"
              @click="openEdit(row)"
              v-if="permission.includes('sys:c37infkcspphhw:edit')">修改
            </el-link>
            <el-popconfirm
              class="ele-action"
              title="确定要删除此库存上传单表吗？"
              @confirm="remove(row)">
              <el-link
                type="danger"
                slot="reference"
                :underline="false"
                icon="el-icon-delete"
                v-if="permission.includes('sys:c37infkcspphhw:delete')">删除
              </el-link>
            </el-popconfirm>
          </template>
        </ele-pro-table>
      </el-card>
      <!-- 编辑弹窗 -->
      <!-- <c37infkcspphhw-edit
        :data="current"
        :visible.sync="showEdit"
        @done="reload"/> -->
    </div>
  </template>

  <script>
  import { mapGetters } from "vuex";
  // import C37InfKcSpphhwEdit from './c37infkcspphhw-edit';

  export default {
    name: 'ExamC37InfKcSpphhw',
    // components: {C37InfKcSpphhwEdit},
    computed: {
      ...mapGetters(["permission"]),
    },
    data() {
      return {
        // 表格数据接口
        url: '/c37infkcspphhw/index',
        // 表格列配置
        columns: [
          {
            columnKey: 'selection',
            type: 'selection',
            width: 45,
            align: 'center',
            fixed: "left"
          },
          {
            prop: 'yezNo',
            label: '编号',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'danwName',
            label: '单位名称',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'shangpNo',
            label: '商品编号',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'chineseName',
            label: '商品名称',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'baozNum',
            label: '包装数量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'baozDanw',
            label: '包装单位',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'yaopGuig',
            label: '药品规格',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'price',
            label: '价格',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'je',
            label: '总金额',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'maker',
            label: '生产厂家',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'lot',
            label: '批号',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'shengchanDate',
            label: '生产日期',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'youxDate',
            label: '有效期至',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'num',
            label: '数量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'js',
            label: '件数',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'lss',
            label: '零散量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'scrq',
            label: '上传日期',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'rukyzNum',
            label: '入库预占数量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'chukykNum',
            label: '出库预扣数量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'buhyzNum',
            label: '补货预占数量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'buhykNum',
            label: '补货预扣数量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'zaitNum',
            label: '在途数量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'suodNum',
            label: '锁定数量',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'zt',
            label: '状态',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center',
            formatter: (row, column, cellValue) => {
            return this.statusFormat(row, column,cellValue);
          }
          },
          // {
          //   prop: 'xiansLoc',
          //   label: '',
          //   showOverflowTooltip: true,
          //   minWidth: 100,
          //   align: 'center'
          // },
          // {
          //   prop: 'ssxkcyr',
          //   label: '',
          //   showOverflowTooltip: true,
          //   minWidth: 100,
          //   align: 'center'
          // },
        ],
        // 表格搜索条件
        where: {},
        // 表格选中数据
        selection: [],
        // 当前编辑数据
        current: null,
        // 是否显示编辑弹窗
        showEdit: false,
      };
    },
    methods: {
      statusFormat(row, column,cellValue) {
        const daterc = row[column.property]
        if(daterc !=null){
            return cellValue.trim()=="N"?"已同步":"未同步";
            }
      },
      /* 刷新表格 */
      reload() {
        this.$refs.table.reload({where: this.where});
      },
      /* 重置搜索 */
      reset() {
        this.where = {};
        this.reload();
      },
      /* 显示编辑 */
      openEdit(row) {
        this.current = row;
        this.showEdit = true;
      },
      /* 删除 */
      remove(row) {
        const loading = this.$loading({lock: true});
        this.$http.delete('/c37infkcspphhw/delete', {id: row.id}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      },
      /* 批量删除 */
      removeBatch() {
        if (!this.selection.length) {
          this.$message.error('请至少选择一条数据');
          return;
        }
        this.$confirm('确定要删除选中的库存上传单表吗?', '提示', {
          type: 'warning'
        }).then(() => {
          const loading = this.$loading({lock: true});
          this.$http.delete('/c37infkcspphhw/delete', {id: this.selection.map(d => d.id)}).then(res => {
            loading.close();
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              this.reload();
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            loading.close();
            this.$message.error(e.message);
          });
        }).catch(() => {
        });
      },
    }
  }
  </script>

  <style scoped>
  </style>
